/**
 * 紫色浮台道具
 */
cc.Class({
    extends: cc.Component,

    properties: {

    },


    onLoad() {
        this.pos = this.node.getPosition();
        this.backNode = cc.find("Canvas/player");
    },


    // 只在两个碰撞体开始接触时被调用一次
    onBeginContact: function (contact, selfCollider, otherCollider) {
        let rigidBody = selfCollider.node.getComponent(cc.RigidBody);
        if (selfCollider.tag === cc.vv.TAG.FLOAT) {
            //将浮块的状态改为动态的，然后延时显示
            setTimeout(() => {
                rigidBody.type = 2;
                let fade = cc.fadeIn();
                selfCollider.node.runAction(fade);
            }, 500)
            //关闭接触监听器
            rigidBody.enabledContactListener = false;
            this.inof();
        }
        //块下落之后延时显示
        setTimeout(() => {
            let fade = cc.fadeIn(2);
            selfCollider.node.runAction(fade);
            this.node.setPosition(this.pos);
            rigidBody.type = 0;
            // rigidBody._b2Body.m_linearVelocity.y = 0;
            //启动接触监听器
            rigidBody.enabledContactListener = true;
        }, 5000)

        setTimeout(() => {
            this.node.active = true;
        }, 5000)
    },

    inof() {
        setTimeout(() => {
            let add = this.backNode.getComponent(cc.RigidBody)._b2Body.m_linearVelocity;
            add.y = 1;
            let rigidBody = this.node.getComponent(cc.RigidBody);
            rigidBody._b2Body.m_linearVelocity.y = -30;
            this.node.active = false;
        }, 1000)


    },
    // start () {},

    //update(dt) {},
});
